/*
Realistic Unit Modification v4.0 Dialog 
v4.0.0.1 [ALPHA]
Concept & Development by Draper & Raps | [VRC]
*/

private["_battery","_target","_order","_time","_typR","_rof","_num","_ldr","_spasht","_guns"];

_battery = _this select 0;
_target = _this select 1;
_order = _this select 2;

//player globalchat format ["%1",_order];

_time = _order select 0;
_typR = _order select 1;
_rof = _order select 2;
_num = _order select 3;

_ldr = units _battery select 0;

_guns = [];
{if!(vehicle _x in _guns)then{_guns = _guns + [vehicle _x]}} foreach units _battery;

_splasht = vehicle _ldr getArtilleryETA [_target, _typR];

//hint format ["%1",_guns];

//_splasht = 0;

[_splasht,_ldr] spawn {
	sleep (_this select 0)-5;
	(_this select 1) sidechat "SPLASH";	
	if(true)exitwith{};
};

//player globalchat format ["%1",_guns];

_guncnt = count _guns;

if (_order select 0 == "IMMEDIATE") then {
	for [{_r=0},{_r<_num},{_r=_r+1}] do {
		_unit = _guns select (_r mod _guncnt);
		_unit commandArtilleryFire [_target, _typR, 1];
		if(_r == 0) then {_ldr sidechat "SHOT"};
		if(_r == (_num-1)) then {_ldr sidechat "ROUNDS COMPLETE"};
		sleep _rof;
	};
	
} else {
	_tstart = time;
	while {(time-_tstart) < _num} do {
		for [{_r=0},{_r<_num},{_r=_r+1}] do {
			_unit = _guns select (_r mod _guncnt);
			_unit commandArtilleryFire [_target, _typR, 1];
			if (_r == 0) then {_ldr sidechat "SHOT"};
			if (_r == (_num-1)) then {_ldr sidechat "ROUNDS COMPLETE"};
			sleep _rof;
		};
		
	};
};

vehicle _ldr setvariable ["ARTY_ONMISSION", false, true];

if(true)exitwith{};